<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" @sendUserSearch="getUserSearch" :searchData="userSearchData" @toAdd="add" exportUrl="/api/admin/export/excel_out_user" :isHaveExport="false" ref="tableComponents">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark" style="width: 99.8%" >
          <!-- <el-table-column type="selection" class="tc" width="35"></el-table-column> -->
          <!-- <el-table-column label="同生号" min-width="50" align="center">
            <template slot-scope="scope">
              <small>{{ scope.row.tsh || "----" }}</small>
            </template>
          </el-table-column> -->

          <el-table-column label="头像" min-width="120">
            <template slot-scope="scope">
              <div class="tc">
                <img style="width: 50px; height: 50px" :src="imgError(scope.row.avatar)" class="user_img" />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="昵称" min-width="120">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{ scope.row.nickname || "----" }}</span>
                </div>
                <div>
                  <span>会员账号：</span>
                  <span>{{ scope.row.username || "---" }}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <!-- <el-table-column label="群昵称" min-width="60" align="center">
            <template slot-scope="scope">
              <small>{{ scope.row.nc || "----" }}</small>
            </template>
          </el-table-column> -->

          <!-- <el-table-column label="头像" min-width="60" align="center">
            <template slot-scope="scope">
              <div class="tc">
                <img
                  style="width: 50px; height: 50px"
                  :src="$fnc.getImgUrl(scope.row.avatar)"
                  class="user_img"
                />
              </div>
            </template>
          </el-table-column> -->

          <el-table-column label="地区" min-width="120" >
            <template slot-scope="scope">
              <small>{{
                scope.row.province +
                "-" +
                scope.row.city +
                "-" +
                scope.row.area +
                "-" +
                scope.row.town
              }}</small>
            </template>
          </el-table-column>

          <el-table-column label="性别" min-width="120" >
            <template slot-scope="scope">
              <small>{{ scope.row.sex_cn}}</small>
            </template>
          </el-table-column>

          <!-- <el-table-column label="生日" min-width="80" align="center">
            <template slot-scope="scope">
              <small>{{
                scope.row.year + "-" + scope.row.month + "-" + scope.row.day
              }}</small>
            </template>
          </el-table-column> -->

          <!-- <el-table-column label="群成员等级" min-width="80" align="center">
            <template slot-scope="scope">
              <small>{{ getRating(scope.row.reply_num) }}</small>
            </template>
          </el-table-column> -->
          <el-table-column label="入群时间" min-width="120">
            <template slot-scope="scope">
              <small>{{ scope.row.created_time | getTimeFormat }}</small>
            </template>
          </el-table-column>

          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <div style="display: flex">
                <!-- <el-button
                  type="primary"
                  @click="editData(scope.row)"
                  size="mini"
                  >设置</el-button
                > -->
                <el-button type="danger" @click="deleteNew(scope.row.id)" size="mini">删除</el-button>
                <!-- <el-button type="danger" size="mini">删除</el-button> -->
              </div>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>

    <el-dialog :close-on-click-modal="false" title="设置" :append-to-body="true" width="400px" v-if="dialogeditVisible" :visible.sync="dialogeditVisible">
      <el-form :label-position="'left'" label-width="70px">
        <!-- <el-form-item label="同生号">
          <el-input disabled v-model="edmsgs.tsh"></el-input>
        </el-form-item> -->
        <el-form-item label="昵称">
          <el-input disabled v-model="edmsgs.nickname"></el-input>
        </el-form-item>
        <el-form-item label="群昵称">
          <el-input v-model="edmsgs.nc"></el-input>
        </el-form-item>
        <!-- <el-form-item label="成员等级">
          <el-select v-model="nowLevel" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="禁言">
          <el-switch v-model="jinyanFlag" active-color="#13ce66" inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
        <el-form-item>
          <el-button @click="confirmEdit" type="primary">确认修改</el-button>
          <el-button @click="edit" type="primary">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { groupUserList } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      collectionsel: "",
      userSearchData: groupUserList,
      list: {},
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      loading: false,
      id: "",
      dialogeditVisible: false,
      edmsgs: {},
      jinyanFlag: true,
      // currentPage
    };
  },
  components: {},
  created() {
    this.id = this.$route.query.id;
    this.getNewsAll();
  },
  methods: {
    getRating(num) {
      if (!num) {
        return "----";
      }
      if (num >= 0 && num <= 10) {
        return "LV1";
      } else if (num > 10 && num <= 50) {
        return "LV2";
      } else if (num > 50 && num <= 200) {
        return "LV3";
      } else if (num > 200 && num <= 1000) {
        return "LV4";
      } else if (num > 1000 && num <= 5000) {
        return "LV5";
      } else {
        return "LV6";
      }
    },
    seePersonList(id) {
      console.log("点击的数", id);
      this.$router.push(`/index/user/groupUserList?id=${id}`);
    },
    handleSelectionChange() {},
    editData(row) {
      this.edmsgs = row;
      this.dialogeditVisible = true;
    },
    async confirmEdit() {
      let params = {};
      params.id = this.edmsgs.id;
      params.nc = this.edmsgs.nc;
      params.flag = this.jinyanFlag;
    },
    editUsers(row) {
      console.log("change", row);
      this.$store.commit("setUserMsg", row);
      this.$router.push("/index/user/userEdit");
    },

    export_user() {
      this.$fnc.postExcelFile({}, "/api/admin/export/excel_out_user");
    },

    clear_ewm_all() {
      this.$swal({
        title: "您确定要清空全部二维码吗",
        text: "清空后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getUser.clear_all_ewm({}).then((res) => {
            if (res.data.code == 200) {
              this.getNewsAll();
            } else {
              this.$swal(res.data.result, "error");
            }
          });
        }
      });
    },

    add() {
      this.addvisible = true;
    },
    isHasImg(pathImg) {
      var ImgObj = new Image();
      ImgObj.src = pathImg;
      if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
        return true;
      } else {
        return false;
      }
    },
    getUserSearch(obj) {
      this.searchAll = obj;
      this.$router.push(this.$route.path + "?page=" + 1);
      this.getNewsAll(obj);
    },
    getUserInfo(id, cate_id, ti) {
      let routeData = this.$router.resolve({
        path: "/index/user/user_info",
        query: { id: id, cate_id: cate_id, title: ti },
      });
      window.open(routeData.href, "_blank");
    },
    imgError(item) {
      if (!item) {
        return require("@/assets/img/default_head.png");
      }
      if (item.indexOf("http") >= 0) {
        return item;
      } else if (item.indexOf("api") >= 0) {
        return item;
      } else {
        return "/api/" + item;
      }
    },
    getNewsAll(data) {
      // this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      for (var i in params) {
        if (params[i] == undefined) {
          params[i] = "";
        }
      }
      params.id = this.id;
      this.$api.getIMteam.teamMateList(params).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;

      this.getNewsAll(params);
      this.pageSize = val;
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.$router.push(this.$route.path + "?page=" + val);
    },

    delSelection() {
      //删除
      this.$swal({
        title: "您确定要删除选中信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          var str = "";
          for (var i in this.multipleSelection) {
            str += this.multipleSelection[i].id + "@";
          }
          str = str.slice(0, -1);
          var data = { id_str: str };
          this.$api.getUser.userDel(data).then((res) => {
            if (res.data.code == 200) {
              this.getNewsAll();
            } else {
              this.$swal(res.data.result, "error");
            }
          });
        }
      });
    },
    deleteNew(id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          var data = { id: id };
          this.$api.getIMteam.teamMateDel(data).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.getNewsAll();
            } else {
              this.$swal(res.data.result, "error");
            }
          });
        }
      });
    },

    reload() {
      this.getNewsAll(this.searchAll);
    },
  },
  beforeCreate() {},
  deactivated() {
    this.searchAll.tid = "";
  },

  watch: {
    $route() {
      var params = this.searchAll;
      params.page = this.$route.query.page || 1;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
      this.currentPage = Number(this.$route.query.page) || 1;
    },
  },
  computed: {},
};
</script>
<style scoped>
.find_btn {
  background: #3a8ee6;
  border-color: #3a8ee6;
  font-weight: 400;

  padding: 2px 8px;
  color: #ffffff;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  margin-left: 5px;
}
</style>
